// import { showLogger, sysLogger } from './logger';
// import { SysMsgType } from '../type/logger';
export enum SysMsgType {
  js = 'js',
  network = 'network',
  res = 'res',
  performance = 'performance',
}

const DEBUGER = import.meta.env.VITE_APP_DEBUGER
/**
 *  * enum LOGLEVEL
 * @LOGLEVEL
 *  1 打印日志 debug  2、打印调试 error 3、打印错误 info  4、  打印信息 warn  5、  打印警告 assert 6、打印断言7、断言 8、清空
 */
export enum LOGLEVEL {
  debug = 'debug',
  error = 'error',
  info = 'info',
  warn = 'warn',
  assert = 'assert',
  clear = 'clear',
}
/**
 * Enum for STYLETYPE values.
 * @readonly
 * @enum {string}
 */
export enum STYLETYPE {
  /** The 日志的文字css，数字，dom，类型打印的值 */
  css = '%c',
  number = '%d',
  dom = '%o',
  object = '%O',
}
/**
 * Enum for MESSAGESTYLE values.
 * @readonly
 * @enum {string}
 */
export enum MESSAGESTYLE {
  debug = 'color: #FFCCFF;font-size: 12px;text-decoration: underline;',
  error = 'color: #990033;font-size: 12px;font-weight: bold;text-decoration: underline;',
  info = 'color: #33FF33;font-size: 12px;text-decoration: underline;',
  warn = 'color: #FFCC00;font-size: 12px;font-weight: bold;text-decoration: underline;',
  assert = 'color: #99FFFF;font-size: 12px;font-weight: bold;text-decoration: underline;',
  clear = 'color: #3366FF;font-size: 12px;font-weight: bold;',
  moudle = 'color: #FF66FF;font-size: 12px;font-weight: bold;',
}

type TLOG = {
  // message: string,
  // messageStyle: MESSAGESTYLE,
  styleType: STYLETYPE //  /** The 日志的文字css，数字，dom，类型打印的值 */
  moudle: string
  level: LOGLEVEL // 日志输出类型
}
/**
 * Interface for ConsoleLogger classes that log and console.
 *
 * @interface ILoger
 */
interface ILoger {
  console: Console
  log: (message: string, type: LOGLEVEL, style: STYLETYPE, ...argc: any) => void
}

/**
 *  * LOG类，日志打印.
 * @class
 * @params {string} moudle - 模块名称文本.
 * @params {string} console - 类型.
 *  1、// 打印日志 debug()  2、// 打印调试 error()  3、// 打印错误 info()  4、 // 打印信息 warn()  5、 // 打印警告 assert() 6、// 打印断言7、断言// 清空
 */
export class ConsoleLogger implements ILoger {
  private logData: TLOG = {
    moudle: '',
    level: LOGLEVEL.info,
    styleType: STYLETYPE.css,
  }

  /**
   * @implements {ILoger}
   */
  console: Console

  /**
   *
   * @params moudle 模块名称
   * @params con 触发打印日志模块，默认console
   */
  constructor(moudle: string, con?: Console) {
    this.logData.moudle = moudle
    this.console = con || window.console
  }

  // clickLogger(message: string, elem: any, ...argc: any[]) {
  //   const level = LOGLEVEL.info;
  //   const style = STYLETYPE.dom;
  //   if (DEBUGER !== 'false') {
  //     const logArgs = [
  //       `${STYLETYPE.css}[${this.logData.moudle}]-[${message}]-{${style}}`,
  //       MESSAGESTYLE[level],
  //       ...argc
  //     ];
  //     this.console[LOGLEVEL[level]](...logArgs);
  //   }

  //   clickLogger({
  //     params: { message, logLevel: level, desc: JSON.stringify(argc) },
  //     elem
  //   });
  // }

  warn(message: string, sysMsgType: SysMsgType, ...argc: any[]) {
    const level = LOGLEVEL.error
    const style = STYLETYPE.css
    if (DEBUGER !== 'false') {
      const logArgs = [
        `${STYLETYPE.css}[${this.logData.moudle}]-[${message}]-{${style}}`,
        MESSAGESTYLE[level],
        ...argc,
      ]
      this.console[LOGLEVEL[level]](...logArgs)
    }

    // sysLogger({
    //   params: { message, desc: JSON.stringify(argc) },
    //   sysMsgType
    // });
  }

  /**
   * @implements {ILoger}
   * @params {string} message 需要打印的信息
   * @params {LOGLEVEL} loglevel 输出文本类型
   * @params {STYLETYPE} styleType 打印文本类型
   * @params argc  扩展
   *  * @returns {void}
   */
  log(message: string, loglevel?: LOGLEVEL | Record<any, any>, ...argc: any[]) {
    let level: LOGLEVEL
    if (typeof loglevel === 'object') {
      level = LOGLEVEL.info
      argc.push(loglevel)
    } else if (loglevel && MESSAGESTYLE[loglevel]) {
      level = loglevel || this.logData.level //默认是info
    } else {
      //传普通字符串
      level = LOGLEVEL.info
      argc.push(loglevel)
    }

    const style = this.logData.styleType
    if (DEBUGER !== 'false') {
      let logArgs = [
        `${STYLETYPE.css}[${this.logData.moudle}]-${style}[${message}]`,
        MESSAGESTYLE.moudle,
        MESSAGESTYLE[level],
        ...argc,
      ]
      switch (style) {
        case STYLETYPE.dom:
          logArgs = [
            `${STYLETYPE.css}[${this.logData.moudle}]-[${message}]-{${style}}`,
            MESSAGESTYLE[level],
            ...argc,
          ]
          break
        case STYLETYPE.object:
          logArgs = [
            `${STYLETYPE.css}[${this.logData.moudle}]-[${message}]-{${style}}`,
            MESSAGESTYLE[level],
            ...argc,
          ]
          break
        default:
          break
      }
      switch (level) {
        case LOGLEVEL.assert:
          this.console[LOGLEVEL.assert](
            ...argc,
            `${this.logData.moudle}:${style + message}`,
            MESSAGESTYLE.assert,
          )
          break
        default:
          this.console[LOGLEVEL[level]](...logArgs)
          break
      }
    }

    // showLogger({ message, desc: JSON.stringify(argc) });
  }
}
const globLogger = new ConsoleLogger('global', console)
export default globLogger
